# 截图抠图
import time
from selenium import webdriver
from PIL import Image

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://www.vip.com/')
time.sleep(5)

logo_ele = driver.find_element("xpath","//img[@id='J-vipLogo']")
# 当前页面截图
driver.save_screenshot("整个页面.png")
# 加载要操作的图片
full_page_img = Image.open("整个页面.png")
# 元素相对位置
print(logo_ele.location) #   {'x': 346, 'y': 30}
# 元素大小
print(logo_ele.size) #   {'height': 100, 'width': 160}
# 图片剪裁
logo_img = full_page_img.crop(
    (logo_ele.location['x'],logo_ele.location['y'],
    logo_ele.location['x']+logo_ele.size['width'],logo_ele.location['y']+logo_ele.size['height']))
# 保存剪裁图片
logo_img.save("logo.png")
